package cn.iocoder.yudao.module.system.dal.mysql.gugu;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.gugu.vo.CollegeScorePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.gugu.CollegeScoreDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 历年高考高校录取分数线数据 Mapper
 */
@Mapper
public interface CollegeScoreMapper extends BaseMapperX<CollegeScoreDO> {

    /**
     * 根据省份、年份和高校名称查询高校录取分数线数据
     *
     * @param province 省份
     * @param year 年份
     * @param collegeName 高校名称
     * @return 高校录取分数线数据列表
     */
    default List<CollegeScoreDO> selectByProvinceYearAndCollegeName(String province, Integer year, String collegeName) {
        return selectList(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eqIfPresent(CollegeScoreDO::getProvince, province)
                .eqIfPresent(CollegeScoreDO::getYear, year)
                .likeIfPresent(CollegeScoreDO::getCollegeName, collegeName)
                .orderByDesc(CollegeScoreDO::getYear)
                .orderByAsc(CollegeScoreDO::getProvince)
                .orderByAsc(CollegeScoreDO::getCollegeName)
                .orderByAsc(CollegeScoreDO::getAdmissionBatch));
    }

    /**
     * 根据省份查询高校录取分数线数据
     *
     * @param province 省份
     * @return 高校录取分数线数据列表
     */
    default List<CollegeScoreDO> selectByProvince(String province) {
        return selectList(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eq(CollegeScoreDO::getProvince, province)
                .orderByDesc(CollegeScoreDO::getYear)
                .orderByAsc(CollegeScoreDO::getCollegeName));
    }

    /**
     * 根据年份查询高校录取分数线数据
     *
     * @param year 年份
     * @return 高校录取分数线数据列表
     */
    default List<CollegeScoreDO> selectByYear(Integer year) {
        return selectList(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eq(CollegeScoreDO::getYear, year)
                .orderByAsc(CollegeScoreDO::getProvince)
                .orderByAsc(CollegeScoreDO::getCollegeName));
    }

    /**
     * 根据高校名称查询高校录取分数线数据
     *
     * @param collegeName 高校名称
     * @return 高校录取分数线数据列表
     */
    default List<CollegeScoreDO> selectByCollegeName(String collegeName) {
        return selectList(new LambdaQueryWrapperX<CollegeScoreDO>()
                .like(CollegeScoreDO::getCollegeName, collegeName)
                .orderByDesc(CollegeScoreDO::getYear)
                .orderByAsc(CollegeScoreDO::getProvince));
    }

    /**
     * 根据高校UUID查询高校录取分数线数据
     *
     * @param schoolUuid 高校UUID
     * @return 高校录取分数线数据列表
     */
    default List<CollegeScoreDO> selectBySchoolUuid(String schoolUuid) {
        return selectList(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eq(CollegeScoreDO::getSchoolUuid, schoolUuid)
                .orderByDesc(CollegeScoreDO::getYear)
                .orderByAsc(CollegeScoreDO::getProvince));
    }

    /**
     * 分页查询高校录取分数线数据
     *
     * @param reqVO 查询条件
     * @return 分页结果
     */
    default PageResult<CollegeScoreDO> selectPage(CollegeScorePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CollegeScoreDO>()
                .eqIfPresent(CollegeScoreDO::getProvince, reqVO.getProvince())
                .eqIfPresent(CollegeScoreDO::getYear, reqVO.getYear())
                .likeIfPresent(CollegeScoreDO::getCollegeName, reqVO.getCollegeName())
                .eqIfPresent(CollegeScoreDO::getSchoolUuid, reqVO.getSchoolUuid())
                .eqIfPresent(CollegeScoreDO::getAdmissionBatch, reqVO.getAdmissionBatch())
                .eqIfPresent(CollegeScoreDO::getTypeName, reqVO.getTypeName())
                .eqIfPresent(CollegeScoreDO::getEnrollmentType, reqVO.getEnrollmentType())
                .eqIfPresent(CollegeScoreDO::getSchoolType, reqVO.getSchoolType())
                .eqIfPresent(CollegeScoreDO::getIs985, reqVO.getIs985())
                .eqIfPresent(CollegeScoreDO::getIs211, reqVO.getIs211())
                .eqIfPresent(CollegeScoreDO::getIsDualClass, reqVO.getIsDualClass())
                .orderByDesc(CollegeScoreDO::getYear)
                .orderByAsc(CollegeScoreDO::getProvince)
                .orderByAsc(CollegeScoreDO::getCollegeName));
    }

    /**
     * 检查指定条件的数据是否已存在
     *
     * @param province 省份
     * @param year 年份
     * @param schoolUuid 高校UUID
     * @param admissionBatch 录取批次
     * @param typeName 文科理科类型
     * @return 是否存在
     */
    default boolean existsByCondition(String province, Integer year, String schoolUuid, String admissionBatch, String typeName) {
        return selectCount(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eq(CollegeScoreDO::getProvince, province)
                .eq(CollegeScoreDO::getYear, year)
                .eq(CollegeScoreDO::getSchoolUuid, schoolUuid)
                .eqIfPresent(CollegeScoreDO::getAdmissionBatch, admissionBatch)
                .eqIfPresent(CollegeScoreDO::getTypeName, typeName)) > 0;
    }

    /**
     * 根据省份、年份、高校UUID、录取批次和文科理科类型删除数据
     *
     * @param province 省份
     * @param year 年份
     * @param schoolUuid 高校UUID
     * @param admissionBatch 录取批次
     * @param typeName 文科理科类型
     * @return 删除的记录数
     */
    default int deleteByCondition(String province, Integer year, String schoolUuid, String admissionBatch, String typeName) {
        return delete(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eq(CollegeScoreDO::getProvince, province)
                .eq(CollegeScoreDO::getYear, year)
                .eq(CollegeScoreDO::getSchoolUuid, schoolUuid)
                .eqIfPresent(CollegeScoreDO::getAdmissionBatch, admissionBatch)
                .eqIfPresent(CollegeScoreDO::getTypeName, typeName));
    }

    /**
     * 根据年份删除数据
     *
     * @param year 年份
     * @return 删除的记录数
     */
    default int deleteByYear(Integer year) {
        return delete(new LambdaQueryWrapperX<CollegeScoreDO>()
                .eq(CollegeScoreDO::getYear, year));
    }
}
